package com.hnzq.cloud.freshorderassembly.exception;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hnzq.cloud.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@ResponseBody
public class FreExceptionHandler {


    //自定义异常
    @ExceptionHandler(FreshException.class)
    public Result DefectTrackingException(FreshException e){
        e.printStackTrace();
        return Result.newInstance().setMessage(e.getMessage()).setCode(e.getCode());
    }

    //运行异常
    @ExceptionHandler(RuntimeException.class)
    public Result RuntimeException(Exception e){
        e.printStackTrace();
        return Result.newInstance().setMessage("运行异常").setCode(500);
    }


    //兜底操作
    @ExceptionHandler(Exception.class)
    public Result Exception(Exception e){
        e.printStackTrace();
        return Result.newInstance().setMessage("有异常").setCode(500);
    }



}
